﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO.Compression;
using System.IO;

namespace Report
{
    public class CompressUtility
    {
        public static byte[] GzipDeCompress(byte[] data)
        {
            MemoryStream ms = new MemoryStream(data);

            GZipStream gs = new GZipStream(ms, CompressionMode.Decompress);

            MemoryStream decompressedMs = new MemoryStream();
            byte[] buffer = new byte[1024];

            int len = 0;
            while ((len = gs.Read(buffer, 0, buffer.Length)) > 0)
            {
                decompressedMs.Write(buffer, 0, len);
            }

            return decompressedMs.ToArray();
        }

        public static byte[] DeflateDeCompress(byte[] data)
        {
            MemoryStream ms = new MemoryStream(data);

            DeflateStream gs = new DeflateStream(ms, CompressionMode.Decompress);

            MemoryStream decompressedMs = new MemoryStream();
            byte[] buffer = new byte[1024];

            int len = 0;
            while ((len = gs.Read(buffer, 0, buffer.Length)) > 0)
            {
                decompressedMs.Write(buffer, 0, len);
            }

            return decompressedMs.ToArray();
        }
    }
}
